<div class="page-body">
    <div class="row">
        <div class="widget">
            <div class="widget-header
            <switch name="T_type">
            <case value="1">bg-magenta</case>
            <case value="2">bg-palegreen</case>
            <case value="3">bg-lightred</case>
            <case value="4">bg-blue</case>
            <case value="5">bg-blueberry</case>
            <case value="6">bg-gold</case>
            <default />bg-magenta
            </switch>
                                ">
            <span class="widget-caption">{$T_title|default=CONTROLLER_NAME}</span>
                                <!--Widget Buttons-->
        </div>
            <div class="widget-body">
                <div id="horizontal-form">
                    <form class="form-horizontal form_buy" role="form"
                          action="{:U('doRefund')}"
                          method="post" enctype="multipart/form-data" onSubmit="return false;">
                        <div class="form-group">
                            <label for="order_id" class="col-sm-3 control-label no-padding-right">订单号：</label>
                            <div class="col-sm-3">
                                <input type="text" autocomplete="off" class="form-control" id="order_id" name="order_id" value="{$Think.get.id}" onkeydown="getOrder()">
                            </div>
                        </div>
                        <hr>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">
                                类型：</label>
                            <div class="col-sm-3">
                                <select id="type" name="type" onchange="getOrder()">
                                    <option value="1" <eq name="Think.get.type" value="1">selected</eq> >购书</option>
                                    <option value="2" <eq name="Think.get.type" value="2">selected</eq> >充值</option>
                                    <option value="3" <eq name="Think.get.type" value="3">selected</eq> >活动报名</option>
                                </select>
                            </div>
                        </div>
                        <hr>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">订单明细：</label>
                            <div class="col-sm-5">
                                <div class="order_detail" style="">

                                </div>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">应退金额：</label>
                            <div class="col-sm-3">
                                <input type="number" id="money" name="money" class="form-control" value=""  disabled="disabled">
                            </div>
                            <div class="col-sm-6">
                                <span class="danger"></span>
                            </div>
                        </div>
                        <div class="form-group   ">
                            <label class="col-sm-3 control-label no-padding-right">实退金额：</label>
                            <div class="col-sm-3">
                                <input type="number" id="money_real" name="money_real" class="form-control" value="">
                            </div>
                            <div class="col-sm-6">
                                <span class="danger"></span>
                            </div>
                        </div>
                        <div class="form-group  ">
                            <div class="col-sm-offset-3 col-sm-10">
                                <p class="label label-darkpink graded error_info"></p><br>
                                <input type="button" class="btn btn-primary" value="提交" onkeypress="FSubmit()" onclick="FSubmit()">
                                <input type="hidden" id="user_id" name="user_id" value="">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script>

    //获取订单信息
    function getOrder() {
        $(".error_info").html('');
        var $order_id = $("#order_id").val();
        var $type = $("#type").val();
        if ($.trim($order_id) == "") {
            return;
        }
        $('.order_detail').html('');
        $.post("{:U('Refund/getOrder')}", {'type': $type, 'order_id': $order_id}, function (data) {
            if (data.status == "success") {

                $str='<span class="info">查询成功</span><br>'+
                        '会员卡：<span class="card_id">'+data.data.card_id+'</span><br>'+
                        '订单号：<span class="order_id">'+data.data.order_id+'</span><br>'+
                        '支付流水号：<span class="pay_id">'+data.data.pay_id+'</span><br>'+
                        '内容：<span class="content">'+data.data.content+'</span><br>'+
                        '交易金额：￥<span class="money">'+data.data.money+'</span><br>'+
                        '订单时间：<span class="create_time">'+data.data.create_time+'</span><br>'+
                        '备注：<span class="remark"></span><br>';
                $('.order_detail').html($str);

            } else {
                $('.order_detail').html(data.data);
            }
            cal_all();
        }, "json");
    }
    //计算总金额及活动折扣价等
    function cal_all() {
        var $money = $(".order_detail .money").html();  //免活动费次数
        if($money==""){
            $money=0;
        }
        $('#money').val($money);
        $('#money_real').val($money);
    }

    //提交
    function FSubmit() {
        if (!confirm('确认操作?')) {
            return;
        }
        if ($("#card_id").val() == "") {
            $(".error_info").html("请输入有效卡号");
            return;
        }
        if ($("#type_id").val() == 0) {
            $(".error_info").html("请选择充值类型");
            return;
        }
        if ($("#money_real").val() == "" || parseFloat($("#money_zero").val()) < 0) {
            $(".error_info").html("请输入实收金额或找零错误");
            return;
        }

//        $(".form_buy").attr("onSubmit", "");
//        $(".form_buy").submit();
//        return true;

        $.post("{:U('Refund/doRefund')}",$('.form_buy').serialize(),function(data){
            if(data.status=="success"){
                getOrder();
                $(".error_info").html(data.data);
            }else{
                getOrder();
                $(".error_info").html(data.data);
            }
        },'json');
    }
</script>